using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Navigation;
namespace MicroMsg.UI.Page
{
	public class WebViewPage : BasePage
	{
		private const string TAG = "WebViewPage";
		private const string cStrImgUrlTag = "imgurl:";
		private const string cStrImgUrlLogTag = "ImgUrlLogTag:";
		private const string cStrProfileTag = "weixin://profile/";
		private string mStrUrl = "";
		public WebViewPageConfig mConfig;
		private bool mIsLoadComplete;
		private string strWebContent = "";
		private string mStrRedirectUrl = "";
		private JsEvent mJsEvent;
		private string mStrCurImgUrl = "";
		private EventWatcher addContactWatcher;
		private EventWatcher getProfileWatcher;
		private MMMessageBox mErrDialog;
		private string mStrUserName = "";
		private Contact mContact;
		private bool mIsJsInvokeSucc;
		private string mStrCurTitle;
		private Stack<Uri> NavigationStack = new Stack<Uri>();
		private ApplicationBarMenuItem shareToBlog;
		private ApplicationBarMenuItem shareToCircle;
		private ApplicationBar mBar;
		internal TextBlock txtTitle;
		internal Grid LayoutRoot;
		internal WebBrowser webView;
		internal PerformanceProgressBar progressCtrl;
		private bool _contentLoaded;
		public WebViewPage()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Page_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
		}
		private void Page_Loaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("WebViewPage", "Page_Loaded");
		}
		private void Page_Unloaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("WebViewPage", "Page_Unloaded");
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("WebViewPage", "OnPageIn");
			if (object_0 != null && object_0.Length != 0)
			{
				this.webView.add_MouseEnter(new MouseEventHandler(this.webView_MouseEnter));
				this.mIsLoadComplete = false;
				this.mIsJsInvokeSucc = false;
				if (object_0[0] is string)
				{
					this.mStrUrl = (object_0[0] as string);
					if (object_0.Length > 1 && object_0[1] is GetA8KeyScene)
					{
						GetA8KeyScene getA8KeyScene = (GetA8KeyScene)object_0[1];
						if (getA8KeyScene != GetA8KeyScene.MMGETA8KEY_SCENE_UNKNOW)
						{
							Log.smethod_5("WebViewPage", "before get A8Key url = " + this.mStrUrl);
							new NetSceneGetA8Key().doScene(this.mStrUrl, getA8KeyScene, new DelegateNavigateToUrl(this.navigateToUrl), GetA8KeyOpCode.MMGETA8KEY_REDIRECT);
							this.progressCtrl.IsIndeterminate = true;
							return;
						}
					}
				}
				else
				{
					if (!(object_0[0] is WebViewPageConfig))
					{
						base.GoBack();
						return;
					}
					this.mConfig = (object_0[0] as WebViewPageConfig);
					this.mStrUrl = this.mConfig.strUrl;
					this.txtTitle.set_Text(this.mConfig.strTitle);
				}
				this.initUI();
				try
				{
					Uri uri = new Uri(this.mStrUrl);
					this.webView.Navigate(uri);
					this.progressCtrl.IsIndeterminate = true;
					this.disableAppbar();
				}
				catch
				{
					base.GoBack();
				}
				return;
			}
		}
		private void navigateToUrl(string string_0)
		{
			Uri uri;
			if (!string.IsNullOrEmpty(string_0))
			{
				uri = new Uri(string_0);
				this.mStrRedirectUrl = string_0;
			}
			else
			{
				uri = new Uri(this.mStrUrl);
			}
			this.webView.Navigate(uri);
		}
		public string getJsString()
		{
			string result = "";
			using (Stream stream = Application.GetResourceStream(new Uri("Resource/Html/wpJs.js", 2)).get_Stream())
			{
				if (stream != null && stream.get_Length() > 0L)
				{
					byte[] array = new byte[stream.get_Length()];
					int num = stream.Read(array, 0, (int)stream.get_Length());
					if (num > 0)
					{
						result = Util.ByteArrayToString(array);
					}
				}
			}
			return result;
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("WebViewPage", "OnPageOut");
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("WebViewPage", "OnPageBack");
		}
		private void onEventSuccess(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs.mEventID != EventConst.ON_NETSCENE_ADDCONTACT_SUCCESS)
			{
				if (evtArgs.mEventID != EventConst.ON_NETSCENE_ADDCONTACT_ERR)
				{
					if (evtArgs.mEventID == EventConst.ON_STORAGE_CONTACT_ADD || evtArgs.mEventID == EventConst.ON_NETSCENE_BATCH_GET_CONTACT_ERR)
					{
						if (evtArgs.mEventID == EventConst.ON_NETSCENE_BATCH_GET_CONTACT_ERR)
						{
							MMMessageBox.Show(strings.Web_Add_Contact_AddFail, true, "确定");
						}
						else
						{
							if (evtArgs.mEventID == EventConst.ON_STORAGE_CONTACT_ADD)
							{
								if (evtArgs.mObject == null || !(evtArgs.mObject is List<object>))
								{
									MMMessageBox.Show(strings.Web_Add_Contact_AddFail, true, "确定");
									return;
								}
								List<Contact> listObject = evtArgs.getListObject<Contact>();
								if (!string.IsNullOrEmpty(this.mStrUserName) && listObject != null)
								{
									using (List<Contact>.Enumerator enumerator = listObject.GetEnumerator())
									{
										while (enumerator.MoveNext())
										{
											Contact current = enumerator.get_Current();
											if (current != null && current.strUsrName == this.mStrUserName)
											{
												this.mContact = current;
												Dialog2BtnWithImg.Show(strings.Enterprise_Follow_brand, this.mContact, strings.Enterprise_Follow, strings.COM_Cancel, "", new Dialog2BtnWithImg.dismissWithClickBtn(this.addContactDialogHandler));
											}
										}
										goto IL_137;
									}
								}
								MMMessageBox.Show(strings.Web_Add_Contact_AddFail, true, "确定");
							}
						}
						IL_137:
						EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.addContactWatcher);
						EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_BATCH_GET_CONTACT_ERR, this.addContactWatcher);
						return;
					}
					return;
				}
			}
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_SUCCESS, this.addContactWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_ERR, this.addContactWatcher);
			this.progressCtrl.IsIndeterminate = false;
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_ADDCONTACT_SUCCESS)
			{
				if (!string.IsNullOrEmpty(this.mStrRedirectUrl))
				{
					this.webView.Navigate(new Uri(this.mStrRedirectUrl));
				}
				if (this.mContact != null)
				{
					ContactMgr.setContact(this.mContact, true);
					StorageMgr.contact.update(this.mContact);
					return;
				}
			}
			else
			{
				if (evtArgs.mEventID == EventConst.ON_NETSCENE_ADDCONTACT_ERR && (this.mErrDialog == null || this.mErrDialog.get_Visibility() != null))
				{
					this.mErrDialog = MMMessageBox.Show(strings.Web_Add_Contact_AddFail, true, "确定");
					return;
				}
			}
		}
		private void addContactDialogHandler(object sender, int nClickIndex)
		{
			if (nClickIndex == 0 && sender != null && sender is Dialog2BtnWithImg && !string.IsNullOrEmpty(this.mContact.strUsrName))
			{
				this.addContactWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventSuccess));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_SUCCESS, this.addContactWatcher);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_ADDCONTACT_ERR, this.addContactWatcher);
				ServiceCenter.sceneVerifyUser.doSceneAddContact(this.mContact.strUsrName, AddContactScene.MM_ADDSCENE_QRCode);
				this.progressCtrl.IsIndeterminate = true;
			}
		}
		private void webView_ScriptNotify(object sender, NotifyEventArgs e)
		{
			string text = e.get_Value().ToString();
			if (string.IsNullOrEmpty(text))
			{
				return;
			}
			try
			{
				if (text.StartsWith("{") && text.EndsWith("}"))
				{
					if (text.IndexOf("params") > 0)
					{
						text = text.Replace("params", "PARAMS");
					}
					JsEvent jsEvent = (JsEvent)Util.GetObjectFromJson(text, typeof(JsEvent));
					if (jsEvent == null)
					{
						return;
					}
					if (jsEvent.func == "addContact" && jsEvent.__msg_type == "call")
					{
						if (string.IsNullOrEmpty(jsEvent.PARAMS.username))
						{
							return;
						}
						this.mStrUserName = jsEvent.PARAMS.username;
						this.mContact = StorageMgr.contact.method_0(this.mStrUserName);
						if (this.mContact != null)
						{
							Dialog2BtnWithImg.Show(strings.Enterprise_Follow_brand, this.mContact, strings.Enterprise_Follow, strings.COM_Cancel, "", new Dialog2BtnWithImg.dismissWithClickBtn(this.addContactDialogHandler));
						}
						else
						{
							List<string> list = new List<string>();
							list.Add(this.mStrUserName);
							ServiceCenter.sceneBatchGetContact.doScene(list);
							this.getProfileWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventSuccess));
							EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.getProfileWatcher);
							EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_BATCH_GET_CONTACT_ERR, this.getProfileWatcher);
						}
						HeadImgMgr.getHeadImage(this.mStrUserName, true);
					}
					else
					{
						if ((!(jsEvent.func == "sendAppMessage") || !(jsEvent.__msg_type == "call")) && (!(jsEvent.func == "profile") || !(jsEvent.__msg_type == "call")))
						{
							if (jsEvent.func == "shareWeibo" && jsEvent.__msg_type == "call")
							{
								this.menuShareToWeibo(jsEvent);
							}
							else
							{
								if (jsEvent.func == "shareTimeline" && jsEvent.__msg_type == "call")
								{
									this.menuShareToCircle(jsEvent);
								}
								else
								{
									if (jsEvent.func == "imagePreview")
									{
										jsEvent.__msg_type == "call";
									}
								}
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				Log.smethod_1("WebViewPage", "JS err = " + ex.get_Message());
			}
			if (text.StartsWith("imgurl:") && text.get_Length() > "imgurl:".get_Length())
			{
				if (text.EndsWith("gif", 5) || !text.Contains("http"))
				{
					return;
				}
				this.mStrCurImgUrl = text.Substring("imgurl:".get_Length());
				Log.smethod_5("WebViewPage", "Get ImgUrl:" + this.mStrCurImgUrl);
			}
			if (text.StartsWith("weixin://profile/") && text.get_Length() > "weixin://profile/".get_Length())
			{
				string text2 = text.Substring("weixin://profile/".get_Length());
				if (!string.IsNullOrEmpty(text2))
				{
					VerifiedPeopleInfo.GotoThisPage(text2, false);
				}
			}
		}
		private void webView_Navigating(object sender, NavigatingEventArgs e)
		{
			string originalString = e.get_Uri().get_OriginalString();
			if (string.IsNullOrEmpty(originalString))
			{
				return;
			}
			if (originalString.StartsWith("weixin://profile/") && originalString.get_Length() > "weixin://profile/".get_Length())
			{
				string text = originalString.Substring("weixin://profile/".get_Length());
				if (!string.IsNullOrEmpty(text))
				{
					VerifiedPeopleInfo.GotoThisPage(text, false);
				}
			}
		}
		private void webView_Navigated(object sender, NavigationEventArgs e)
		{
			this.progressCtrl.IsIndeterminate = true;
			this.disableAppbar();
			this.NavigationStack.Push(e.get_Uri());
		}
		private bool isNeedAddJs(string string_0)
		{
			bool result = false;
			if (!string.IsNullOrEmpty(this.mStrRedirectUrl) && this.mStrRedirectUrl != this.mStrUrl)
			{
				result = true;
			}
			else
			{
				if (string_0.Contains("y.qq.com/i/song"))
				{
					result = true;
				}
			}
			return result;
		}
		private void webView_LoadCompleted(object sender, NavigationEventArgs e)
		{
			this.mIsLoadComplete = true;
			try
			{
				this.mStrCurTitle = this.webView.InvokeScript("eval", new string[]
				{
					"document.title"
				}).ToString();
				this.mStrCurImgUrl = "";
				this.getShareImgUrl();
				this.invokeProfileBtnJs();
				string text = this.webView.SaveToString();
				if (text.Contains("WeixinJSBridgeReady"))
				{
					string jsString = this.getJsString();
					this.webView.InvokeScript("eval", new string[]
					{
						jsString
					});
					this.webView.InvokeScript("setDefaultEventHandlers");
					this.webView.InvokeScript("startOnWeixinReady");
					this.mIsJsInvokeSucc = true;
				}
			}
			catch (SystemException ex)
			{
				Log.smethod_1("WebViewPage", "JS err = " + ex.get_Message());
				this.mIsJsInvokeSucc = false;
			}
			base.set_ApplicationBar(this.GetApplicationBar());
			this.enableAppbar();
			this.progressCtrl.IsIndeterminate = false;
		}
		private void webView_MouseEnter(object sender, MouseEventArgs e)
		{
		}
		private void initUI()
		{
			if (this.mConfig != null && this.mConfig.mBHideAppbar)
			{
				this.webView.set_Height(800.0);
			}
			else
			{
				this.webView.set_Height(800.0);
			}
			this.webView.UpdateLayout();
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			this.webView.set_Height(800.0);
			this.webView.UpdateLayout();
		}
		public static void GotoThisPage(object object_0, GetA8KeyScene scene = GetA8KeyScene.MMGETA8KEY_SCENE_UNKNOW)
		{
			ToolFunction.GotoPageForUserControl("/Source/UI/Util/WebViewPage.xaml", new object[]
			{
				object_0,
				scene
			}, false);
		}
		private void enableAppbar()
		{
			if (base.get_ApplicationBar() != null)
			{
				base.get_ApplicationBar().set_IsMenuEnabled(true);
				IEnumerator enumerator = base.get_ApplicationBar().get_Buttons().GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						ApplicationBarIconButton applicationBarIconButton = (ApplicationBarIconButton)enumerator.get_Current();
						applicationBarIconButton.set_IsEnabled(true);
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
			}
		}
		private void disableAppbar()
		{
			if (base.get_ApplicationBar() != null)
			{
				base.get_ApplicationBar().set_IsMenuEnabled(false);
				IEnumerator enumerator = base.get_ApplicationBar().get_Buttons().GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						ApplicationBarIconButton applicationBarIconButton = (ApplicationBarIconButton)enumerator.get_Current();
						applicationBarIconButton.set_IsEnabled(false);
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
			}
		}
		public ApplicationBar GetApplicationBar()
		{
			if (this.mConfig != null && this.mConfig.mBHideAppbar)
			{
				return null;
			}
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.webView.set_Height(768.0);
			});
			if (this.mBar != null)
			{
				if (!this.mBar.get_IsVisible())
				{
					this.mBar.set_IsVisible(true);
				}
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			this.mBar.set_Mode(1);
			this.shareToCircle = new ApplicationBarMenuItem(strings.Reader_Share_To_Album_Title);
			this.shareToCircle.add_Click(new EventHandler(this.menuCircle_Click));
			this.mBar.get_MenuItems().Add(this.shareToCircle);
			if (AccountMgr.nBindQQ > 999u)
			{
				this.shareToBlog = new ApplicationBarMenuItem(strings.Reader_Share_To_Weibo_Title);
				this.shareToBlog.add_Click(new EventHandler(this.menuBlog_Click));
				this.mBar.get_MenuItems().Add(this.shareToBlog);
			}
			this.setAppBarStyle(this.mBar);
			return this.mBar;
		}
		private void menuBlog_Click(object sender, EventArgs e)
		{
			if (!AccountMgr.HasTWeibo())
			{
				MessageBoxManager.ShowToast(strings.Setting_NoTentcentWeibo, 2500, null, false);
				return;
			}
			if (this.mIsJsInvokeSucc)
			{
				try
				{
					string text = "{\"__msg_type\":\"event\", \"__event_id\":\"menu:share:weibo\"}";
					this.webView.InvokeScript("handleWeixinMessage", new string[]
					{
						text
					});
					return;
				}
				catch (Exception ex)
				{
					Log.smethod_1("WebViewPage", ex.get_Message());
					this.menuShareToWeibo(null);
					return;
				}
			}
			this.menuShareToWeibo(null);
		}
		private void menuCircle_Click(object sender, EventArgs e)
		{
			if (this.mIsJsInvokeSucc)
			{
				try
				{
					string text = "{\"__msg_type\":\"event\", \"__event_id\":\"menu:share:timeline\"}";
					this.webView.InvokeScript("handleWeixinMessage", new string[]
					{
						text
					});
					return;
				}
				catch (Exception)
				{
					this.menuShareToCircle(null);
					return;
				}
			}
			this.menuShareToCircle(null);
		}
		public void menuShareToWeibo(JsEvent jsEvent = null)
		{
			string reader_Share_To_Weibo_Title = strings.Reader_Share_To_Weibo_Title;
			string text = "40;" + this.GetShareShortUrl();
			string text2 = this.mStrCurTitle + " " + this.GetShareShortUrl();
			if (jsEvent != null && jsEvent.PARAMS != null)
			{
				if (!string.IsNullOrEmpty(jsEvent.PARAMS.content))
				{
					text2 = jsEvent.PARAMS.content;
				}
				if (!string.IsNullOrEmpty(jsEvent.PARAMS.String_1))
				{
					text = "40;" + jsEvent.PARAMS.String_1;
				}
			}
			ToolFunction.GotoPageForUserControl("/Source/Plugin/TXBlogRead/UI/EditBlogContentPage.xaml", new object[]
			{
				SendCardType.MM_SENDCARD_READER,
				reader_Share_To_Weibo_Title,
				text,
				text2
			}, false);
		}
		public void menuShareToCircle(JsEvent jsEvent = null)
		{
			string reader_Share_To_Album_Title = strings.Reader_Share_To_Album_Title;
			string title = this.GetTitle();
			string img_url = this.mStrCurImgUrl;
			string text = this.GetShareUrl();
			if (jsEvent != null)
			{
				if (jsEvent.PARAMS != null)
				{
					if (!string.IsNullOrEmpty(jsEvent.PARAMS.title))
					{
						title = jsEvent.PARAMS.title;
					}
					if (!string.IsNullOrEmpty(jsEvent.PARAMS.img_url))
					{
						img_url = jsEvent.PARAMS.img_url;
					}
					if (!string.IsNullOrEmpty(jsEvent.PARAMS.link))
					{
						text = jsEvent.PARAMS.link;
					}
				}
				this.mJsEvent = jsEvent;
			}
			ToolFunction.GotoPageForUserControl("/Source/Plugin/TXBlogRead/UI/EditCircleContentPage.xaml", new object[]
			{
				new EditCircleContentPage.DelegateComment(this.onBoxReturnHandler),
				reader_Share_To_Album_Title,
				title,
				text,
				img_url
			}, false);
		}
		public void onBoxReturnHandler(string strComment)
		{
			string title = this.GetTitle();
			string img_url = this.mStrCurImgUrl;
			string strContentUrl = this.GetShareUrl();
			string strDescription = this.GetShareUrl();
			if (this.mJsEvent != null && this.mJsEvent.PARAMS != null)
			{
				if (!string.IsNullOrEmpty(this.mJsEvent.PARAMS.title))
				{
					title = this.mJsEvent.PARAMS.title;
				}
				if (!string.IsNullOrEmpty(this.mJsEvent.PARAMS.img_url))
				{
					img_url = this.mJsEvent.PARAMS.img_url;
				}
				if (!string.IsNullOrEmpty(this.mJsEvent.PARAMS.link))
				{
					strContentUrl = this.mJsEvent.PARAMS.link;
				}
				if (!string.IsNullOrEmpty(this.mJsEvent.PARAMS.desc))
				{
					strDescription = this.mJsEvent.PARAMS.desc;
				}
			}
			SnsInfo snsObj = SnsPostService.createShareSnsObject(new ContentObject
			{
				strContentUrl = strContentUrl,
				strTitle = title,
				strDescription = strDescription,
				mediaList = this.getImgList(img_url)
			}, Util.NullAsNil(strComment), SnsObjectType.MMSNS_OBJECT_FEED);
			SnsPostService.shareToTimeLine(snsObj);
		}
		private List<TloMedia> getImgList(string strImgUrl)
		{
			List<TloMedia> list = null;
			if (string.IsNullOrWhiteSpace(strImgUrl))
			{
				return list;
			}
			list = new List<TloMedia>();
			list.Add(new TloMedia
			{
				nType = 2,
				strUrl = strImgUrl,
				nUrlType = 1,
				strThumb = strImgUrl,
				nThumbType = 1,
				nID = 0uL
			});
			return list;
		}
		private void Font_Click(object sender, EventArgs e)
		{
		}
		public string GetDigestFromObj()
		{
			return "";
		}
		public string GetShareShortUrl()
		{
			if (this.mConfig != null && !string.IsNullOrEmpty(this.mConfig.strShareShortUrl))
			{
				return this.mConfig.strShareShortUrl;
			}
			if (this.NavigationStack.get_Count() != 0)
			{
				return Enumerable.First<Uri>(this.NavigationStack).get_OriginalString();
			}
			if (this.mStrUrl != null)
			{
				return this.mStrUrl;
			}
			return "";
		}
		public string GetShareUrl()
		{
			if (this.mConfig != null && !string.IsNullOrEmpty(this.mConfig.strShareUrl))
			{
				return this.mConfig.strShareUrl;
			}
			if (this.NavigationStack.get_Count() != 0)
			{
				return Enumerable.First<Uri>(this.NavigationStack).get_OriginalString();
			}
			if (this.mStrUrl != null)
			{
				return this.mStrUrl;
			}
			return "";
		}
		public string GetTitle()
		{
			if (!string.IsNullOrEmpty(this.mStrCurTitle))
			{
				return this.mStrCurTitle;
			}
			if (this.mConfig != null)
			{
				return this.mConfig.strTitle;
			}
			return "";
		}
		private string getShareImgUrl()
		{
			string text = "window.BindLinks = function() {\r\n\r\n                var isCalled = false;\r\n\r\n                var callCB = function(_img){\r\n                  if (isCalled) {return;};\r\n                  isCalled = true;  \r\n\r\n                  window.external.notify('imgurl:'+_img);\r\n                }\r\n\r\n                var logCB = function(_img){\r\n                  window.external.notify('ImgUrlLogTag:'+_img);\r\n                }\r\n\r\n                var _allImgs = document.getElementsByTagName('img');\r\n                if (_allImgs.length==0) {\r\n                  return logCB('not find');\r\n                }\r\n\r\n                // 过滤掉重复的图片\r\n                var _srcs = {};\r\n                var allImgs = [];\r\n                for (var i = 0; i < _allImgs.length; i++) {\r\n                  var _img = _allImgs[i];\r\n                  if (_srcs[_img.src]) {\r\n                    // added\r\n                  } else {\r\n                    _srcs[_img.src] = 1; // mark added\r\n                    allImgs.push(_img);\r\n                  }\r\n                };\r\n\r\n                var results = [];\r\n\r\n                var img;\r\n                for (var i = 0; i < allImgs.length && i < 20; i++) {\r\n                  img = allImgs[i];\r\n                  logCB('Got img:' + 'h=' + img.height + ',w=' + img.width + ',url=' + img.src);\r\n                  var newImg = new Image();\r\n                  newImg.onload = function() {\r\n                    this.isLoaded = true;\r\n                    var loadedCount = 0;\r\n                    logCB('Img load:' + 'h=' + this.height + ',w=' + this.width + ',url=' + this.src);\r\n                    for (var j = 0; j < results.length; j++) {\r\n                      var res = results[j];\r\n                      if (!res.isLoaded) {\r\n                        break;\r\n                      }\r\n                      loadedCount++;\r\n                      if (res.width>289 && res.height>289) {\r\n                        callCB(res.src);\r\n                        break;\r\n                      }\r\n                    }\r\n                    if (loadedCount==allImgs.length) {\r\n                      // 全部都已经加载完了，但还是没有找到。\r\n                      logCB('load all but no img');\r\n                    };\r\n                  }\r\n                  newImg.src = img.src;\r\n                  results.push(newImg);\r\n                }\r\n\r\n                setTimeout(function(){\r\n                  for (var j = 0; j < results.length; j++) {\r\n                    var res = results[j];\r\n                    if (!res.isLoaded) {\r\n                      continue;\r\n                    }\r\n                    if (res.width>289 && res.height>289) {\r\n                      callCB(res.src);\r\n                      return;\r\n                    }\r\n                  }\r\n                  callCB('time out nothing get');\r\n                },1000);\r\n              }";
			string text2 = "";
			string result;
			try
			{
				this.webView.InvokeScript("eval", new string[]
				{
					text
				});
				text2 = this.webView.InvokeScript("BindLinks").ToString();
				goto IL_57;
			}
			catch
			{
				Log.smethod_5("WebViewPage", "InvokeScript crash");
				result = null;
			}
			return result;
			IL_57:
			if (string.IsNullOrEmpty(text2))
			{
				return null;
			}
			if (text2.EndsWith("gif", 5))
			{
				return null;
			}
			return text2;
		}
		private void invokeProfileBtnJs()
		{
			this.webView.InvokeScript("eval", new string[]
			{
				"\r\n                window.onProfileLinkPressed = function() {\r\n                    var elem = event.srcElement;\r\n                    for(var i = 0; i< 7 && elem != null && elem.tagName != 'a' && elem.tagName != 'A'; i++)\r\n                    {\r\n                        window.external.notify('get elem ' + i + ', tag name =' + elem.tagName);\r\n                        elem = elem.parentElement;\r\n                    }\r\n                    \r\n                    if ( elem != null ) {\r\n                        window.external.notify('' + elem.href);\r\n                    }\r\n                    return false;\r\n                }\r\n\r\n                window.BindProfileClicks = function() {\r\n                    var elems = document.getElementsByTagName('a');\r\n                    for (var j = 0; j < elems.length; j++) {\r\n                        var elem = elems[j];\r\n                        if (elem != null && elem.className == 'appItem')\r\n                        {\r\n                            elem.attachEvent('onmousedown', onProfileLinkPressed);\r\n                        }\r\n                    }\r\n                  }\r\n                    \r\n                "
			});
			this.webView.InvokeScript("BindProfileClicks");
		}
		private void small_Click(object sender, RoutedEventArgs e)
		{
			this.webView.InvokeScript("changefont", new string[]
			{
				"1"
			});
		}
		private void middle_Click(object sender, RoutedEventArgs e)
		{
			this.webView.InvokeScript("changefont", new string[]
			{
				"2"
			});
		}
		private void big_Click(object sender, RoutedEventArgs e)
		{
			this.webView.InvokeScript("changefont", new string[]
			{
				"3"
			});
		}
		private void large_Click(object sender, RoutedEventArgs e)
		{
			this.webView.InvokeScript("changefont", new string[]
			{
				"4"
			});
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Util/WebViewPage.xaml", 2));
			this.txtTitle = (TextBlock)base.FindName("txtTitle");
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.webView = (WebBrowser)base.FindName("webView");
			this.progressCtrl = (PerformanceProgressBar)base.FindName("progressCtrl");
		}
	}
}
